<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /*  
         有这样一个 字符串 " http://www.baidu.com?a=1&b=2&c=&d=xxx&a=2 "，
         要求转化成
         { "a": [1,2], "b":2, "c":, "d": xxx }
        */
       let url = 'http://www.baidu.com?a=1&b=2&c=&d=xxx&a=2&a=3'

       function foo(str) {
           console.log(str)
           let a = str.split("?")[1].split("&")
           let newObj = {}
           console.log(a)
           for(let i=0; i<a.length; i++) {
               let item = a[i].split("=")

               if(!newObj.hasOwnProperty(item[0])) {
                   if(item[1] == '') {
                    newObj[item[0]] = null
                   } else {
                        newObj[item[0]] = item[1]
                   }
               } else {
                    newObj[item[0]] = [...newObj[item[0]],item[1]]
               }
           }
           return newObj
       }

       console.log(foo(url))

     
    </script>
</body>
</html>